In [4]:
import csv
with open("guns.csv", "r") as f:
reader = csv.reader(f)
data = list(reader)
In [5]:
print(data[:5])
In [6]:
headers = data[:1]
data = data[1:]
print(headers)
print(data[:5])
In [7]:
years = [row[1] for row in data]
year_counts = {}
for year in years:
if year not in year_counts:
year_counts[year] = 0
year_counts[year] += 1
year_counts
Out[7]:
In [8]:
import datetime
dates = [datetime.datetime(year=int(row[1]), month=int(row[2]), day=1) for row in data]
dates[:5]
Out[8]:
In [9]:
date_counts = {}
for date in dates:
if date not in date_counts:
date_counts[date] = 0
date_counts[date] += 1
date_counts
Out[9]:
In [10]:
sexes = [row[5] for row in data]
sex_counts = {}
for sex in sexes:
if sex not in sex_counts:
sex_counts[sex] = 0
sex_counts[sex] += 1
sex_counts
Out[10]:
In [11]:
races = [row[7] for row in data]
race_counts = {}
for race in races:
if race not in race_counts:
race_counts[race] = 0
race_counts[race] += 1
race_counts
Out[11]:
It appears from the data that males have been killed by gun violence 4x more than females. The data in the race column suggest that whites and blacks account for the majority of deaths to gun violence.
Also, gun deaths seem to peak in the summer and decrease in the winter months.
In [12]:
import csv
with open("census.csv", "r") as f:
reader = csv.reader(f)
census = list(reader)
census
Out[12]:
In [13]:
mapping = {
"Asian/Pacific Islander": 15159516 + 674625,
"Native American/Native Alaskan": 3739506,
"Black": 40250635,
"Hispanic": 44618105,
"White": 197318956
}
race_per_hundredk = {}
for k,v in race_counts.items():
race_per_hundredk[k] = (v / mapping[k]) * 100000
race_per_hundredk
Out[13]:
In [14]:
intents = [row[3] for row in data]
homicide_race_counts = {}
for i,race in enumerate(races):
if race not in homicide_race_counts:
homicide_race_counts[race] = 0
if intents[i] == "Homicide":
homicide_race_counts[race] += 1
race_per_hundredk = {}
for k,v in homicide_race_counts.items():
race_per_hundredk[k] = (v / mapping[k]) * 100000
race_per_hundredk
Out[14]:
According to this data, it appears that homicide rates affect black and hispanic far greater than other racial groups.
In [ ]: